using System;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace SyncComm.Service.Host
{
    internal static class ExtensionsMethods
    {
        /// <summary>
        /// Return basic information of referenced serviceHost object.
        /// </summary>
        /// <param name="serviceHost">The service host.</param>
        /// <returns></returns>
        public static string ToFormattedString(this ServiceHost serviceHost)
        {
            var info = new StringBuilder();
            //get SyncComm Service version
            info.AppendLine(serviceHost.Description.ServiceType.Assembly.ToString());
            //print Endpoints
            info.AppendLine("Service Endpoints:"); 
            serviceHost.Description.Endpoints.ToList()
                .ForEach(e =>
                             {
                                 info.AppendLine(String.Format("\tUri:           {0}", e.ListenUri.ToString()));
                                 info.AppendLine(String.Format("\tClose Timeout: {0}", e.Binding.CloseTimeout)); 
                                 info.AppendLine(String.Format("\tOpen Timeout:  {0}", e.Binding.OpenTimeout));
                             });
            return info.ToString();
        }
    }
}